﻿using System;
using System.Windows.Documents;
using System.Windows.Markup;
using VisualWip.Core;
using VisualWip.Core.Columns;

namespace VisualWip.PresentationModel.Text
{
    public class RichTextColumnViewModel : ColumnViewModelBase
    {
        private readonly RichTextColumn _richTextColumn;

        public RichTextColumnViewModel(Application application, RichTextColumn column, IColumnBuilder columnBuilder)
            : base(application, column, columnBuilder)
        {
            _richTextColumn = column;
        }

        public FlowDocument Document
        {
            get {
                if (!string.IsNullOrWhiteSpace(_richTextColumn.Document))
                {
                    try
                    {
                        return XamlReader.Parse(_richTextColumn.Document) as FlowDocument;
                    }
                    catch (Exception)
                    {
                    }
                }
                return new FlowDocument();
            }
        }

        protected override void ColumnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.ColumnPropertyChanged(sender, e);
            BubbleOnPropertyChanged(e, ()=> Document);
        }

    }
}